﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;



public partial class ViewAssignmentStudent : System.Web.UI.Page
{
    public static int assId;
    static object userId;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            assId = Convert.ToInt32(Request.QueryString["AssignmentId"]);
            userId = Request.QueryString["UserId"];
            if (assId != null)
                setControlValues();
        }
    }

    private void setControlValues()
    {
        string assignFile = "";
        string[] fileName;
        DataSet dsAssignment = new DataSet();
        dsAssignment = AdminCreateTestDAL.GetAssignInfoByAssignId(assId);
        lablAssignmentName.Text = dsAssignment.Tables[0].Rows[0][1].ToString();
        lablSubject.Text = dsAssignment.Tables[0].Rows[0][2].ToString();
        lablTopic.Text = dsAssignment.Tables[0].Rows[0][3].ToString();

        ddlStatus.SelectedIndex = -1;
        ddlStatus.SelectedIndex = ddlStatus.Items.IndexOf(ddlStatus.Items.FindByText(dsAssignment.Tables[1].Rows[0][3].ToString()));

        DataTable dtUser = new DataTable();
        dtUser = AdminCreateTestDAL.GetUserName(userId);
        lablStudentName.Text = dtUser.Rows[0][0].ToString();

       
        DataTable dtUserAss = new DataTable();
        dtUserAss = AdminCreateTestDAL.GetUserAssignment(assId, userId);
        assignFile= dtUserAss.Rows[0][0].ToString();
        fileName = assignFile.Split('/');
        linkdownload.Text = fileName[2];
        linkdownload.NavigateUrl = dtUserAss.Rows[0][0].ToString();
        

        DataTable dtHistor=new DataTable();
        dtHistor=AdminCreateTestDAL.GetAssignmentHistory(assId, userId);
        string text = "";
        for (int i = 0; i < dtHistor.Rows.Count; i++)
        {
            text += dtHistor.Rows[i][0].ToString() + "<br/>";
            lablHistory.Text = text;
        }
       
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        AdminCreateTestDAL.SetAssignmentStatus(assId,userId,ddlStatus.SelectedItem.Text,ddlGrade.SelectedItem.Text, txtRemarks.Text);
        clearAll();
    }
    protected void btnClear_Click(object sender, EventArgs e)
    {
        clearAll();
    }

    private void clearAll()
    {
        txtRemarks.Text = "";
        ddlStatus.SelectedIndex = -1;
    }
}